package cn.qingfeng.a006_rpc2.config;

import cn.qingfeng.a006_rpc2.protocol.Serializer;
import io.netty.util.internal.StringUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
    static Properties properties;

    static {
        try (InputStream in = Config.class.getResourceAsStream("/application.properties")) {
            properties = new Properties();
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Serializer.Algorithm getSerialierAlgorithm() {
        String serialierAlgorithm = properties.getProperty("serializer.algorithm");
        if (StringUtil.isNullOrEmpty(serialierAlgorithm)) {
            return Serializer.Algorithm.Java;
        } else {
            return Serializer.Algorithm.valueOf(serialierAlgorithm);
        }
    }
}
